// MyContext.js
import { createContext, useState, useContext } from 'react';

const MyContext = createContext();

export const MyProvider = ({ children }) => {
    const [data, setData] = useState(null);

    const fetchData = async () => {
        // 模拟异步操作，例如从API获取数据
        const response = await fetch('https://api.example.com/data');
        const result = await response.json();
        setData(result);
    };

    return (
        <MyContext.Provider value={{ data, fetchData }}>
            {children}
        </MyContext.Provider>
    );
};

export const useMyContext = () => useContext(MyContext);
